/*
 * rectangle.c
 *
 *  Created on: Jul 4, 2008
 *      Author: Carlos Oliveira
 */
#include <stdlib.h>
#include <stdio.h>

#include "shape_rectangle.h"
#include "drawPrimitives.h"

static void drawRect(Shape *shape)
{
	ShapeRectangle *r = (ShapeRectangle*)shape;
	draw_rectangle(shape->context, r->x1, r->y1, r->x2, r->y2);
}

static void deleteRect(void *r)
{
	free(r);
	printf("delete a rectangle\n");
}

static int numDefiningPointsRect()
{
	return 2;
}

static ShapeVTable rectangleVTable = {
		drawRect,
		deleteRect,
		numDefiningPointsRect
};


ShapeRectangle *rect_new(GContext context,
		int x1, int y1, int x2, int y2)
{
	ShapeRectangle *r =
		(ShapeRectangle*)malloc(sizeof(ShapeRectangle));
	if (!r) return 0;
	r->x1 = x1;
	r->y1 = y1;
	r->x2 = x2;
	r->y2 = y2;
	r->shape.vtable = &rectangleVTable;
	r->shape.context = context;
	return r;
}
